package xy.donate.android.ui.fragment

import android.content.Intent
import android.os.Bundle
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.fragment_mine.*
import xy.donate.android.R
import xy.donate.android.common.MyFragment
import xy.donate.android.constant.Constant
import xy.donate.android.helper.MmkvHelper
import xy.donate.android.ui.activity.*

class MineFragment : MyFragment<HomeActivity?>() {
    private val orderIntent = Intent()

    override fun getLayoutId(): Int {
        return R.layout.fragment_mine
    }

    override fun initView() {
        orderIntent.setClass(requireActivity(),OrderListActivity::class.java)
        iv_header.setOnClickListener {
            startActivity(PersonalDataActivity::class.java)
        }
        sb_setting.setOnClickListener {
            startActivity(SettingActivity::class.java)
        }
        sb_address.setOnClickListener {
            startActivity(AddressActivity::class.java)
        }
        to_order_detail.setOnClickListener {
            startActivity(OrderListActivity::class.java)
        }
        count_dfk.setOnClickListener {
            orderIntent.putExtra("index",0)
            startActivity(orderIntent)
        }
        count_dps.setOnClickListener {
            orderIntent.putExtra("index",1)
            startActivity(orderIntent)
        }
        count_ywc.setOnClickListener {
            orderIntent.putExtra("index",2)
            startActivity(orderIntent)
        }
        count_dpj.setOnClickListener {
            orderIntent.putExtra("index",3)
            startActivity(orderIntent)
        }
        sb_record.setOnClickListener {
            startActivity(RecordListActivity::class.java)
        }
    }

    override fun initData() {

    }

    override fun onResume() {
        super.onResume()
        if (MmkvHelper.getInstance().mmkv.containsKey(Constant.USER_HEADER)){
            Glide.with(iv_header)
                    .load(MmkvHelper.getInstance().mmkv.getString(Constant.USER_HEADER,""))
                    .circleCrop()
                    .error(R.drawable.avatar_placeholder_ic)
                    .into(iv_header)
        }
    }

    companion object {
        @JvmStatic
        fun newInstance(): MineFragment {
            val args = Bundle()
            val fragment = MineFragment()
            fragment.arguments = args
            return fragment
        }
    }
}